package com.google.code.jtasks.connection;

import java.io.Serializable;

/**
 * Used to identify and represent each task repository used by an application.
 */
public final class TaskRepoId implements Serializable
{
	private static final long serialVersionUID = 1L;

	private final String idString;

	/**
	 * Constructs a new {@link TaskRepoId} instance.
	 * 
	 * @param idString
	 *            The case-sensitive {@link String} that uniquely identifies the task repository represented
	 *            by this {@link TaskRepoId}. Please note that leading and trailing whitespace will be trimmed
	 *            from this {@link String}.
	 */
	public TaskRepoId(String idString)
	{
		if (idString == null || idString.trim().length() <= 0)
			throw new IllegalArgumentException("Invalid ID string: " + idString);

		this.idString = idString.trim();
	}

	/**
	 * Returns the case-sensitive {@link String} that uniquely identifies the task repository represented by
	 * this {@link TaskRepoId}. Please note that leading and trailing whitespace will be trimmed from this
	 * {@link String}.
	 * 
	 * @return the case-sensitive {@link String} that uniquely identifies the task repository represented by
	 *         this {@link TaskRepoId}
	 */
	public String getIdString()
	{
		return idString;
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj)
	{
		if (obj == null || !(obj instanceof TaskRepoId))
			return super.equals(obj);
		TaskRepoId other = (TaskRepoId) obj;

		return idString.equals(other.idString);
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode()
	{
		return idString.hashCode();
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString()
	{
		StringBuilder debugText = new StringBuilder();
		debugText.append(this.getClass().getSimpleName());
		debugText.append("[");
		debugText.append("idString=");
		debugText.append(idString);
		debugText.append("]");
		return debugText.toString();
	}
}